package ssi.cameraTest;

import java.io.IOException;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;

import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class CustomCameraView extends SurfaceView {
   Camera camera;
   SurfaceHolder previewHolder;
   
   public CustomCameraView(Context context) {
      super(context);
      previewHolder= this.getHolder();
      previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
      SurfaceHolder.Callback surfaceHolderListener=new SurfaceHolder.Callback() {
		@Override
		public void surfaceDestroyed(SurfaceHolder holder) {
			camera.stopPreview();
			camera.release();
		}
		
		@Override
		public void surfaceCreated(SurfaceHolder holder) {
			try {
				camera=Camera.open();
				camera.setPreviewDisplay(previewHolder);
			} catch (IOException e) {
				e.printStackTrace();
			}
			
		}
		
		@Override
		public void surfaceChanged(SurfaceHolder holder, int format, int width,
				int height) {
			System.out.println(width +"x" + height);
			Parameters params=camera.getParameters();
			params.setPreviewSize(800, 600);
			params.setPictureFormat(PixelFormat.JPEG);
			camera.startPreview();
			
		}
		 
	};
	previewHolder.addCallback(surfaceHolderListener);
   }   
   
   public double getHorizontalAngle() {
	   return 50.0;   
   }
   
   public double getVerticalAngle() {
	   return 0;
   }
}